home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbnws104.zip / IQUEUE.ZIP / STACKS.BAS < prev   
BASIC Source File  |  1990-07-18  |  2KB  |  52 lines

  1.         DEFINT A-Z
  2.  
  3. '    A demo program which shows the use of the Stack and Queue
  4. '    routines discussed in "Improving Your IQUEUE".  The source
  5. '    for the MASM functions is in the .ASM files.
  6. '
  7. ' The following routines are all in STAQUE.LIB, which you can make into
  8. ' a QLB file by...
  9. '                         LINK /q staque,,nul,bqlb45; (or whatever LIB you need)
  10.  
  11.         DECLARE SUB IQPut (intval%)      'put an item in the queue
  12.         DECLARE FUNCTION IQget% ()       'get an item from the queue
  13.         DECLARE FUNCTION IQfree% ()      'TRUE if any room in queue
  14.         DECLARE FUNCTION IQavail% ()     'TRUE if anything in queue
  15.         DECLARE SUB IQflush ()           'clear (empty) the queue
  16.  
  17.         DECLARE SUB ISPush (ival%)       'put an item on the stack
  18.         DECLARE FUNCTION ISpop% ()       'get an item off the stack
  19.         DECLARE FUNCTION ISfree% ()      'TRUE if any room on stack
  20.         DECLARE FUNCTION ISavail% ()     'TRUE if anything on stack
  21.         DECLARE SUB ISClear ()           'clear the stack
  22.  
  23.         CLS
  24.         k = 0
  25.         DO WHILE IQfree                  'while any room in queue
  26.             k = k + 1                     'put a different item
  27.             IQPut k                       'into each queue slot
  28.         LOOP
  29.         PRINT k; "items originally enqueued"
  30.         FOR j = 1 TO 99                  'now take out some items
  31.             k = IQget                     'and throw them away
  32.         NEXT
  33.         PRINT j - 1; " items dequeued"
  34.         k = 0
  35.         DO WHILE IQfree                  'now put items again until full
  36.             k = k + 1
  37.             IQPut k
  38.         LOOP
  39.         PRINT k; "additional items enqueued"
  40.         k = 0
  41.         DO WHILE ISfree AND IQavail      'while room on stack and data in queue
  42.             k = k + 1                     'count items
  43.             ISPush IQget                  'move from queue to stack
  44.         LOOP
  45.         PRINT k; "items dequeued and pushed"
  46.         PRINT " Popping all items now"
  47.         DO WHILE ISavail                 'now pop items while any remain
  48.             PRINT ISpop;
  49.         LOOP
  50.         PRINT
  51.  
  52.